package ibm.cognos.imt.template

import ibm.cognos.imt.chart.V2BubbleChart
import groovy.xml.MarkupBuilder

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 5/16/14
 * Time: 4:58 PM
 * To change this template use File | Settings | File Templates.
 */
class V2BubbleChartTemplate extends AbstractTemplate{
    V2BubbleChart chart

    V2BubbleChartTemplate(V2BubbleChart v2BubbleChart) {
        chart = v2BubbleChart
    }

    @Override
    def generateTemplateSpec(MarkupBuilder builder) {
        builder.v2_bubbleChart(refQuery: "${chart.queryName}", maxHotspots: "10000", name: "${chart.name}", changeShapeByCategory: "false") {
            v2_basicTooltips()
            v2_bubbleSizing{
                v2_bubbleZero()
            }
            v2_legend(legendSeperator:","){
                v2_legendPosition{
                    v2_legendPreset()
                }
                v2_legendTitle(refQuery: "$chart.queryName"){
                    v2_chartTextContents{
                        v2_automaticText()
                    }
                    style{
                        defaultStyles{
                            defaultStyle(refStyle: "lx")
                        }
                    }
                }
                style{
                    defaultStyles{
                        defaultStyle(refStyle: "lg")
                    }
                }
            }
            v2_yAxis{
                v2_axisRange{
                    v2_automaticRange()
                }
                v2_axisLine(lineWeight:"0")
                v2_majorGridlines(lineColor: "#CCCCCC", lineWeight: "0")
                v2_axisLabels{
                    style{
                        defaultStyles{
                            defaultStyle(refStyle: "al")
                        }
                    }
                }
                v2_axisTitle(refQuery: "$chart.queryName"){
                    v2_chartTextContents{
                        v2_automaticText()
                    }
                    style{
                        defaultStyles{
                            defaultStyle(refStyle: "at")
                        }
                    }
                }
                v2_chartMeasure(refDataItem:"$chart.yAxisMeasure")
            }
            v2_xAxis{
                v2_axisRange{
                    v2_automaticRange()
                }
                v2_axisLine(lineWeight:"0")
                v2_majorGridlines(lineColor: "#CCCCCC", lineWeight: "0")
                v2_axisLabels{
                    style{
                        defaultStyles{
                            defaultStyle(refStyle: "al")
                        }
                    }
                }
                v2_axisTitle(refQuery: "$chart.queryName"){
                    v2_chartTextContents{
                        v2_automaticText()
                    }
                    style{
                        defaultStyles{
                            defaultStyle(refStyle: "at")
                        }
                    }
                }
                v2_chartMeasure(refDataItem:"$chart.xAxisMeasure")
            }
            style{
                defaultStyles{
                    defaultStyle(refStyle: "ch")
                }
                CSS(value:"width:500px;height:400px")

            }
            noDataHandler{
                contents{
                    block{
                        contencts{
                            textItem{
                                dataSource{
                                    staticValue("No Data Available")
                                }
                                style{
                                    CSS(value:"padding:10px 18px;")
                                }
                            }
                        }
                    }
                }
            }
            v2_pointPalette(markerBorders: "show") {
                v2_pointPaletteEntries{
                    palette.each{ k, v ->
                        v2_pointPaletteEntry{
                            v2_fillEffect(defaultColor:"$k"){
                                v2_solidColor(color:"$v")
                            }
                        }
                    }
                }
            }
            v2_series{
                chartNodes{
                    chartNode{
                        chartNodeMembers{
                            chartNodeMember(refDataItem:"$series"){
                                chartContents{
                                    chartTextItem{
                                        dataSource{
                                            memberCaption()
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
            }
            v2_category{
                chartNodes{
                    chartNode{
                        chartNodeMembers{
                            chartNodeMember(refDataItem:"$chart.category"){
                                chartContents{
                                    chartTextItem{
                                        dataSource{
                                            memeberCaption()
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            v2_bubbleMeasure(refDataItem: "$chart.bubbleMeasure")


        }
    }

    @Override
    def getTemplateNode() {
        root = new XmlSlurper().parseText(getSpecStr())
        root
    }
}
